package com.zhaolulu.service;

import com.zhaolulu.mapper.OrderMapper;
import com.zhaolulu.pojo.Order;
import com.zhaolulu.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
public class OrderService {

    @Autowired
    private OrderMapper orderMapper;
    @Autowired
    private RestTemplate restTemplate;
    public Order queryOrderById(Long orderId) {
        // 1.查询订单
        Order order = orderMapper.findById(orderId);
        //        2.查询用户
//        String url = "http://order-service/user/" +  order.getUser_id();
        String url = "http://localhost:8081/user/" +  order.getUser_id();
        //使用restTemplate的时候，需要把OrderServiceApplication里面的@LoadBalanced注释掉
        User user = restTemplate.getForObject(url, User.class);
        // 3.封装user信息
        order.setUser(user);
        // 4.返回
        return order;
    }
}
